package com.guigu.servicegoods.controller;


import com.guigu.common_util.pojo.utils.Result;
import com.guigu.servicegoods.domain.TbPara;
import com.guigu.servicegoods.service.TbParaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@RestController
@RequestMapping("/servicegoods/para")
public class TbParaController {

    @Autowired
    private TbParaService paraService;

    @PostMapping("fingPage")
    public Result findPage(@RequestBody(required = false) Map<String,Object> searchMap,Integer page,Integer size){
        return paraService.findPage(searchMap,page,size);
    }

    // 添加
    @PostMapping("insert")
    public Result insert(@RequestBody TbPara para){
        boolean save = paraService.save(para);
        if (save){
            return Result.ok();
        }
        return Result.error();
    }

    // 修改
    @PostMapping("update")
    public Result update(@RequestBody TbPara para){
        boolean update = paraService.updateById(para);
        if (update){
            return Result.ok();
        }
        return Result.error();
    }

    // 删除
    @GetMapping("delete")
    public Result delete(Integer id){
        boolean remove = paraService.removeById(id);
        if (remove){
            return Result.ok();
        }
        return Result.error();
    }

    // 根据ID查询
    @GetMapping("findById")
    public Result findById(Integer id){
        TbPara para = paraService.getById(id);
        if (para == null){
            return Result.error();
        }
        return Result.ok().data("para",para);
    }
}

